package org.longs;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.longs.bean.ImageFile;
import org.longs.bean.WasHeader;
import org.longs.converter.WasConverter;
import org.longs.converter.WdfConverter;

import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileFilter;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Main {
    private static String path = "src/main/resources/";
    private static String[] role = new String[]{"飞燕女", "英女侠", "偃无师", "巫蛮儿", "杀破狼", "逍遥生", "剑侠客", "狐美人", "骨精灵", "舞天姬", "玄彩娥", "桃夭夭", "虎头怪", "神天兵", "龙太子", "巨魔王", "鬼潇潇", "羽灵神"};
    private static long[] key = new long[]{1295847816, 1853525647L, 1076954610L, 3552721044L, 3990239921L, 3366615112L, 2782337201L, 3771134163L, 1462708813L,
            2715893287L, 3002376600L, 3991654351L, 993860032L, 2666294756L, 454787878L, 1382010105L, 2912848813L, 3919700593L, 477926852L, 352380776L,
            811687356L, 915719759L, 4249060934L, 1336751228L, 1950021903L, 2235513801L, 3594739784L, 1960900090L, 2382390242L, 1537855326L, 3907030953L,
            2290431679L, 3202252097L, 4033571742L, 1492820992L, 655187057L, 2901001332L, 3190903022L, 298183232L, 1945354141L, 3436623848L, 1724964988L,
            2592865169L, 3393696884L, 1494002331L, 1310769894L, 1152800681L, 2542768010L, 1378600591L, 2829693277L, 3846038890L, 3901444948L, 68667698L,
            3331959614L, 432707334L, 4241851683L, 3448703702L, 2542506275L, 241536076L, 314448958L, 2242677963L, 1887092560L, 1489631920L, 2860202818L,
            4076591726L, 4232189420L, 3498505860L, 4241140149L, 3858705890L, 2271353759L, 3452523393L, 963399171L, 2959831232L, 2917226350L, 4215743335L,
            3987108486L, 365569753L, 3701218951L, 3044567112L, 3265766525L, 2129343522L, 2401287726L, 2716317030L, 292723042L, 4014574629L, 4183102172L,
            4115700508L, 2139528734L, 276624883L, 4099788650L, 2578443618L, 3367759523L, 576638850L, 3586214754L, 2830927389L, 1915332364L, 1341579386L,
            3743372972L, 1217313750L, 1208397371L, 156713767L, 2057251015L, 3084935361L, 1485268859L, 470535714L, 2868631088L, 3835251562L, 2896374671L,
            3982186902L, 1708428735L, 2448085336L, 1354708809L, 943667221L, 1146784672L, 3592760724L, 611393967L, 1688780051L, 2042812914L, 1466206851L,
            3612578974L};

    private static long[] key2 = new long[]{0X047A251BL, 0XD07C8C7BL,0XD8E6F9A5L,0XDA07B03BL,0XDCCFB47EL,0XDE35A6C0L,0XDEA84608L,0XE06AA308L,0XE1ED15BBL,0XE47DA824L,0XECD1D654L,0XF4831403L,0XF6427212L,
            0XF6EBDE4CL,0XCC7F0159L,0X047D0BD0L,0X0F7FA3E5L,0X1C9419F8L,0X1D3F0301L,0X2C3FC5BBL,0X30981FA2L,0X3A7BCB44L,0X3FB960DEL,0X42A7366BL,0X44210711L,
            0X4F692A7BL,0X4FD80C52L,0X50220D93L,0X50D0D23EL,0X521DA1C0L,0X52BB4A65L,0X640A80F4L,0X65FBF6CCL,0X6E92200BL,0X74697B48L,0X776ACD4EL,0X80DE00A6L,
            0X8CCD4B6DL,0X8D177ED8L,0X8D6D0DEEL,0X8D956A19L,0X9EEFD716L,0XA4DFBD47L,0XACA57AF5L,0XB260288CL,0XB328C05FL,0XB9ADFF5CL,0XBA1A56B3L,0XBA1E074FL,
            0XBAB5A3A9L,0XBD043668L,0XC29278D3L,0XC29DE5D7L,0XC64B89DDL};

    public static void main(String[] args) throws IOException {
//        XlsRead xlsRead = new XlsRead(path + "NPC数据.xls");
//        List<Map<String, String>> converter = xlsRead.converter();
//        converter.remove(0);
//        converter.remove(0);


//        //解析wdf
//        final ArrayList<WdfConverter> list = new ArrayList<>();
//        WdfConverter zyWdfConverter = new WdfConverter("src/main/resources/ZY.dll");
//        zyWdfConverter.analysis();
//        list.add(zyWdfConverter);
//        WdfConverter wpWdfConverter = new WdfConverter("src/main/resources/WP.dll");
//        wpWdfConverter.analysis();
//        list.add(wpWdfConverter);
//        WdfConverter wp1WdfConverter = new WdfConverter("src/main/resources/WP1.dll");
//        wp1WdfConverter.analysis();
//        list.add(wp1WdfConverter);
//        WdfConverter itemWdfConverter = new WdfConverter("src/main/resources/item.dll");
//        itemWdfConverter.analysis();
//        list.add(itemWdfConverter);
//        WdfConverter jSWdfConverter = new WdfConverter("src/main/resources/JS.dll");
//        jSWdfConverter.analysis();
//        WdfConverter zhsWdfConverter = new WdfConverter("src/main/resources/ZHS.dll");
//        zhsWdfConverter.analysis();
//        WdfConverter jmWdfConverter = new WdfConverter("src/main/resources/JM.dll");
//        jmWdfConverter.analysis();
//
////
////        //解析wdf并转换成png
//        XlsRead xlsRead = new XlsRead(path + "item.xls");
//        List<Map<String, String>> converter = xlsRead.converter();
//        converter.remove(0);
//        converter.remove(0);
//        WdfConverter wdfConverter;
//        for (Map<String, String> map : converter) {
//            String json = map.get("文件");
//            if (json == null || json.isEmpty()) {
//                continue;
//            }
//            switch (json) {
//                case "WP.dll":
//                case "ZY.dll":
//                case "WP1.dll":
//                case "item.dll":
//                    break;
//                default:
//                    continue;
//            }
//            File dir = getDir(map.get("名称").trim());
//            if (dir == null) continue;
//            String sciNum = map.get("大图标");
//            if (sciNum != null) {
//                if (sciNum.endsWith(".0") && !sciNum.contains("E")) {
//                    sciNum = sciNum.replace(".0", "");
//                }
//                BigDecimal bd = new BigDecimal(sciNum);
//                String normalNum = bd.toPlainString();
//                extracted(normalNum, "大图标", list, dir, false);
//            }
//            sciNum = map.get("小图标");
//            if (sciNum != null) {
//                if (sciNum.endsWith(".0") && !sciNum.contains("E")) {
//                    sciNum = sciNum.replace(".0", "");
//                }
//                BigDecimal bd = new BigDecimal(sciNum);
//                String normalNum = bd.toPlainString();
//                extracted(normalNum, "小图标", list, dir, false);
//            }
//        }


////        for (int i = converter.size() - 1; i >= 0; i--) {
////            if(converter.get(i).get("战斗资源")!=null) {
////                converter.remove(i);
////                continue;
////            }
////            if(converter.get(i).get("资源")!=null&&(converter.get(i).get("资源").equals("ZHS.dll")||converter.get(i).get("资源").equals("MAX.7z"))){
////                converter.remove(i);
////                continue;
////            }
////            boolean flag = true;
////            for (String s : role) {
////                if (converter.get(i).get("名称").contains(s)) {
////                    flag = false;
////                    break;
////                }
////            }
////            if (!flag) {
////                converter.remove(i);
////            }
////        }
//        WdfConverter wdfConverter;
//        for (Map<String, String> map : converter) {
//            String name = map.get("名称");
//            if (name.equals("GM") || name.equals("string")) {
//                continue;
//            }
//            String json = map.get("战斗资源");
//            if (json == null || json.isEmpty()) {
//                continue;
//            }
//            switch (json) {
////                case "JS.dll":
////                    wdfConverter = jSWdfConverter;
////                    break;
////                case "ZY.dll":
////                    wdfConverter = zyWdfConverter;
////                    break;
//                case "ZHS.dll":
//                    wdfConverter = zhsWdfConverter;
//                    break;
////                case "JM.dll":
////                    wdfConverter = jmWdfConverter;
////                    break;
//                default:
//                    continue;
//            }
//            File dir = getDir(name);
//            if (dir == null) continue;
//            getFight(map, dir, wdfConverter);
//            json = map.get("资源");
//            if (json == null || json.isEmpty()) {
//                continue;
//            }
//            switch (json) {
////                case "JS.dll":
////                    wdfConverter = jSWdfConverter;
////                    break;
////                case "ZY.dll":
////                    wdfConverter = zyWdfConverter;
////                    break;
//                case "ZHS.dll":
//                    wdfConverter = zhsWdfConverter;
//                    break;
////                case "JM.dll":
////                    wdfConverter = jmWdfConverter;
////                    break;
//                default:
//                    continue;
//            }
////            //创建目录
//            getDefault(map, dir, wdfConverter);
//            json = map.get("头像资源");
//            if (json == null || json.isEmpty()) {
//                continue;
//            }
//            switch (json) {
//                case "JS.dll":
//                    wdfConverter = jSWdfConverter;
//                    break;
//                case "ZY.dll":
//                    wdfConverter = zyWdfConverter;
//                    break;
//                case "ZHS.dll":
//                    wdfConverter = zhsWdfConverter;
//                    break;
//                case "JM.dll":
//                    wdfConverter = jmWdfConverter;
//                    break;
//                default:
//                    continue;
//            }
//            dir = new File(path + "/data/" + name + "/图片");
//            if (!dir.exists()) {
//                boolean result = dir.mkdir();
//                if (result) {
//                    System.out.println("目录已创建");
//                } else {
//                    System.out.println("目录未能创建");
//                }
//            }
//            String sciNum = map.get("中头像");
//            if (sciNum != null) {
//                System.out.println(sciNum);
//                if (sciNum.endsWith(".0") && !sciNum.contains("E")) {
//                    sciNum = sciNum.replace(".0", "");
//                }
//                BigDecimal bd = new BigDecimal(sciNum);
//                String normalNum = bd.toPlainString();
//                extracted(normalNum, "中头像", wdfConverter, dir, false);
//            }
//            sciNum = map.get("大头像");
//            if (sciNum != null) {
//                if (sciNum.endsWith(".0") && !sciNum.contains("E")) {
//                    sciNum = sciNum.replace(".0", "");
//                }
//                BigDecimal bd = new BigDecimal(sciNum);
//                String normalNum = bd.toPlainString();
//                extracted(normalNum, "大头像", wdfConverter, dir, false);
//            }
//            sciNum = map.get("小头像");
//            if (sciNum != null) {
//                System.out.println(sciNum);
//                if (sciNum.endsWith(".0") && !sciNum.contains("E")) {
//                    sciNum = sciNum.replace(".0", "");
//                }
//                BigDecimal bd = new BigDecimal(sciNum);
//                String normalNum = bd.toPlainString();
//                extracted(normalNum, "小头像", wdfConverter, dir, false);
//            }
//        }

//            json = map.get("头像组");
//            if (json != null) {
//                dir = new File(path + "/data/" + name + "/图片");
//                if (!dir.exists()) {
//                    boolean result = dir.mkdir();
//                    if (result) {
//                        System.out.println("目录已创建");
//                    } else {
//                        System.out.println("目录未能创建");
//                    }
//                }
//                ObjectMapper mapper = new ObjectMapper();
//                AvaterBean jsonBean = mapper.readValue(json, AvaterBean.class);
//                extracted(jsonBean.getCreation(), "创建", wdfConverter, dir);
//                extracted(jsonBean.getProp(), "道具", wdfConverter, dir);
//                extracted(jsonBean.getCreateAvatar(), "创建头像", wdfConverter, dir);
//                extracted(jsonBean.getCharacter(), "人物", wdfConverter, dir);
//                extracted(jsonBean.getCharacter(), "头像", wdfConverter, dir);
//            }
//        }
//        }
//        FileInputStream inputStream = new FileInputStream(path + "text.dll");
//
//        byte[] bytes = new byte[inputStream.available()];
//        boolean b = inputStream.read(bytes, 0, bytes.length) != -1;
//        ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
//        BufferedImage read = ImageIO.read(stream);
//        System.out.println(read);

//        Actuator.WdfConverterPng("src/main/resources/item.dll", "src/main/resources/tupian/");
//        Actuator.WdfConverterSpirit("src/main/resources/wdf/smap.dll", "src/main/resources/spirit/");

//        Actuator.extracted("src/main/resources",new File("src/main/resources/3819908601537.dll"));
//        Actuator.WdfConverterSpiritToName("src/main/resources/wdf/JM.dll", "src/main/resources/", "0xFF205590");
//        Actuator.WdfConverterWav("src/main/resources/wdf/sound.wdf", "src/main/resources/data");
//        Actuator.test("src/main/resources/ZY.dll", "src/main/resources/");
//        for (int i = 1010; i <= 1018; i++) {
//            Actuator.wasConverterPng("src/main/resources/" + i + ".was", "src/main/resources/",i);
//        }
//        Actuator.wasConverterPng("src/main/resources/was/0x00000020.was", "src/main/resources/");
//        Actuator.wasConverterSpirit("src/main/resources/was/16778087.was", "src/main/resources/");
//        Actuator.mapConverterPng("src/main/resources/map/", "src/main/resources/content/");
//            Actuator.extracted( "src/main/resources/result/", new File("src/main/resources/Dt/3819908601344.dll"));
//        final File file = new File(path + "data");
//        for (File directory : Objects.requireNonNull(file.listFiles())) {
//            directory(file);
//        }
        //我想读取resources下的model目录并打印目录名称
//        File dir = new File("src/main/resources/scene");
//        File[] files = dir.listFiles((d, name) -> name.endsWith(".png"));
//        if (files != null) {
//            for (File file : files) {
//                try {
//                    BufferedImage originalImage = ImageIO.read(file);
//                    int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
//
//                    BufferedImage resizeImage = resizeImage(originalImage, type);
//                    ImageIO.write(resizeImage, "png", file);
//
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//        extracted2();
        System.out.println("Hello world!");
    }

    private static void extracted2() throws IOException {
        final File dir = new File("G:/迅雷下载/role/role");
        final File file = new File(path + "npc.json");
        final List<JSONObject> list = new ArrayList<>();
        if (file.exists()) {
            final JSONArray jsonArray = JSON.parseArray(Files.readAllBytes(file.toPath()));
            for (Object object : jsonArray) {
                final JSONObject jsonObject = (JSONObject) object;
                final Object npc_model = jsonObject.get("npc_model");
                boolean flag = true;
                for (File listFile : dir.listFiles()) {
                    if (listFile.getName().equals(npc_model)) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    list.add(jsonObject);
                }
            }
        }
        final File contentDir = new File(path + "content");
        for (JSONObject object : list) {
            final File npcModel = new File(contentDir.getAbsoluteFile() + File.separator + object.get("npc_model"));
            if (!npcModel.exists()) {
                npcModel.mkdir();
            }
        }
        for (File listFile : contentDir.listFiles()) {
            final File fileDir = new File("E:/GoGameClient/resources/image");
            File[] files = fileDir.listFiles(pathname -> {
                if (pathname.getName().contains(".import")) {
                    return false;
                }
                return pathname.getName().contains(listFile.getName());
            });
            for (File source : files) {
                final File avatar = new File(listFile.getAbsoluteFile() + File.separator + "头像");
                if (!avatar.exists()) {
                    avatar.mkdir();
                }
                final File target = new File(avatar.getAbsoluteFile() + File.separator + source.getName().replace("_", "").replace("坐", "").replace("身体", "").replace(listFile.getName(), ""));
                if (!target.exists()) {
                    Files.copy(source.toPath(), target.toPath());
                }
            }
            final File modelDir = new File("E:/GoGameClient/resources/model");
            files = modelDir.listFiles(pathname -> {
                if (pathname.getName().contains(".import")) {
                    return false;
                }
                final String[] split = pathname.getName().split("_");
                if (split[1].equals("玄彩娥")) {
                    return false;
                }
                if (split[1].equals("骨精灵")) {
                    return false;
                }

                return split[0].equals(listFile.getName());
            });

            for (File source : files) {
                final File model = new File(listFile.getAbsoluteFile() + File.separator + "默认");
                if (!model.exists()) {
                    model.mkdir();
                }
                File target;
                if (source.getName().contains("身体")) {
                    target = new File(model.getAbsoluteFile() + File.separator + source.getName()
                            .replace("_", "")
                            .replace("坐", "")
                            .replace("进阶", "")
                            .replace("身体", "")
                            .replace(listFile.getName(), "")
                            .replace(".json", "_2.json")
                            .replace(".png", "_2.png"));
                } else {
                    target = new File(model.getAbsoluteFile() + File.separator + source.getName().replace("_", "").replace("坐", "").replace("进阶", "").replace("身体", "").replace(listFile.getName(), ""));
                }
                if (!target.exists()) {
                    Files.copy(source.toPath(), target.toPath());
                    System.out.println(source);
                    System.out.println(target);
                }
            }
        }
    }


    private static int updateName(String name) {
        Long i = Long.parseLong(name, 16);
        if (i == 3468445205L) {
            return 1001;
        }
        if (i == 3566134173L) {
            return 1002;
        }
        if (i == 3038955283L) {
            return 1004;
        }
        if (i == 3043296434L) {
            return 1005;
        }
        if (i == 1128733891L) {
            return 1006;
        }
        if (i == 3690484265L) {
            return 1007;
        }
        if (i == 117994174L) {
            return 1008;
        }
        if (i == 2866991463L) {
            return 1009;
        }
        if (i == 0x184AA512L) {
            return 1216;
        }
        if (i == 4269786701L) {
            return 1040;
        }
        if (i == 2914736228L) {
            return 1041;
        }
        if (i == 502306430L) {
            return 1042;
        }
        if (i == 2766803400L) {
            return 1070;
        }
        if (i == 975993013L) {
            return 1090;
        }
        if (i == 647087968L) {
            return 1091;
        }
        if (i == 2930683699L) {
            return 1092;
        }
        if (i == 1209177817L) {
            return 1110;
        }
        if (i == 2159282308L) {
            return 1111;
        }
        if (i == 1803093190L) {
            return 1114;
        }
        if (i == 545106797L) {
            return 1116;
        }
        if (i == 3579377767L) {
            return 1118;
        }
        if (i == 2802830440L) {
            return 1119;
        }
        if (i == 4174697543L) {
            return 1120;
        }
        if (i == 1236030791L) {
            return 1121;
        }
        if (i == 2600205256L) {
            return 1122;
        }
        if (i == 1795111495L) {
            return 1127;
        }
        if (i == 353472097L) {
            return 1128;
        }
        if (i == 3380408013L) {
            return 1129;
        }
        if (i == 3387504035L) {
            return 1130;
        }
        if (i == 1632323059L) {
            return 1131;
        }
        if (i == 2990212588L) {
            return 1135;
        }
        if (i == 1157479725L) {
            return 1138;
        }
        if (i == 3628602651L) {
            return 1241;
        }
        if (i == 4169572890L) {
            return 1380;
        }
        if (i == 2744072561L) {
            return 1139;
        }
        if (i == 3787222136L) {
            return 1140;
        }
        if (i == 3394273965L) {
            return 1142;
        }
        if (i == 206717537L) {
            return 1146;
        }
        if (i == 1267498697L) {
            return 1150;
        }
        if (i == 1389007272L) {
            return 1173;
        }
        if (i == 3293723566L) {
            return 1174;
        }
        if (i == 1051142943L) {
            return 1177;
        }
        if (i == 4288252057L) {
            return 1178;
        }
        if (i == 695155995L) {
            return 1179;
        }
        if (i == 584117065L) {
            return 1180;
        }
        if (i == 1732546758L) {
            return 1181;
        }
        if (i == 3528941268L) {
            return 1182;
        }
        if (i == 3940428598L) {
            return 1183;
        }
        if (i == 1408014958L) {
            return 1186;
        }
        if (i == 2284090720L) {
            return 1187;
        }
        if (i == 1381541766L) {
            return 1188;
        }
        if (i == 254963317L) {
            return 1189;
        }
        if (i == 801213330L) {
            return 1190;
        }
        if (i == 2500598663L) {
            return 1191;
        }
        if (i == 2730614272L) {
            return 1192;
        }
        if (i == 606476023L) {
            return 1193;
        }
        if (i == 544232211L) {
            return 1198;
        }
        if (i == 2027355398L) {
            return 1201;
        }
        if (i == 1070238810L) {
            return 1202;
        }
        if (i == 4040069189L) {
            return 1203;
        }
        if (i == 3355516657L) {
            return 1204;
        }
        if (i == 3409668280L) {
            return 1205;
        }
        if (i == 3262911017L) {
            return 1207;
        }
        if (i == 1428468522L) {
            return 1208;
        }
        if (i == 664467571L) {
            return 1210;
        }
        if (i == 923673984L) {
            return 1218;
        }
        if (i == 3524163775L) {
            return 1211;
        }
        if (i == 638705710L) {
            return 1221;
        }
        if (i == 1186890765L) {
            return 1226;
        }
        if (i == 2308357598L) {
            return 1228;
        }
        if (i == 2642996577L) {
            return 1229;
        }
        if (i == 1530927343L) {
            return 1231;
        }
        if (i == 867489325L) {
            return 1232;
        }
        if (i == 3059022311L) {
            return 1233;
        }
        if (i == 3029783778L) {
            return 1235;
        }
        if (i == 1412756833L) {
            return 1242;
        }
        if (i == 2697825210L) {
            return 1501;
        }
        if (i == 855890337L) {
            return 1506;
        }
        if (i == 3363079713L) {
            return 1507;
        }
        if (i == 2421848661L) {
            return 1508;
        }
        if (i == 3118617574L) {
            return 1511;
        }
        if (i == 876001261L) {
            return 1512;
        }
        if (i == 3729625326L) {
            return 1513;
        }
        if (i == 818673142L) {
            return 1514;
        }
        if (i == 1797992103L) {
            return 1532;
        }
        if (i == 964351559L) {
            return 1920;
        }
        if (i == 0x63033A32L) {
            return 1126;
        }
        if (i == 0x1F812A17L) {
            return 1003;
        }
        if (i == 0x42DA91A8L) {
            return 1251;
        }
        if (i == 0x32DC91D8L) {
            return 1250;
        }
        if (i == 1930050866L) {
            return 1249;
        }
        if (i == 1538345049L) {
            return 1217;
        }
        return 0;
    }


    private static BufferedImage resizeImage(BufferedImage originalImage, int type) {
        int IMG_WIDTH = originalImage.getWidth();
        int IMG_HEIGHT = originalImage.getHeight();
        double scale = 1.0d;
        if (IMG_WIDTH > 1080) {
            scale = 1080.0 / IMG_WIDTH;
            IMG_WIDTH = 1080;
            IMG_HEIGHT = (int) (IMG_HEIGHT * scale);
        }
        BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
        AffineTransform at = new AffineTransform();
        at.scale(scale, scale);
        AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
        resizedImage = scaleOp.filter(originalImage, resizedImage);
        return resizedImage;
    }

    private static void directory(File file) throws IOException {
        if (file.isDirectory()) {
            final File[] files = file.listFiles();
            if (files.length != 2) {
                System.out.println(file.getName());
            }
        }
    }

//    private static void directory(File file) throws IOException {
//        if (file.isDirectory()) {
//            for (File directory : Objects.requireNonNull(file.listFiles())) {
//                directory(directory);
//            }
//        } else {
////            if (file.getName().endsWith("png")) {
////                return ;
////            }
//            if (file.getName().endsWith("was")) {
//                file.delete();
//            }
////            if (file.getAbsolutePath().contains("图片")) {
////                file.delete();
////            }
////            Actuator.wasConverterSpirit(file.getAbsolutePath(), file.getParentFile().getAbsolutePath(),file.getName());
//        }
//    }


    private static File getDir(String name) {
        File dir;
        if (name.contains("_")) {
            String s = name.split("_")[0];
            if ("非迭代".equals(s)) {
                return null;
            }
            //创建目录
            final String[] split = name.split("_");
            dir = new File(path + "/data/");
            for (int i = split.length - 1; i >= 0; i--) {
                dir = new File(dir.getAbsolutePath() + File.separator + split[i]);
                if (!dir.exists()) {
                    boolean result = dir.mkdir();
                    if (result) {
                        System.out.println("目录已创建");
                    } else {
                        System.out.println("目录未能创建");
                    }
                }
            }
        } else {
            String dirPath = path + "/data/" + name; // 替换为实际的目录路径
            dir = new File(dirPath);
            if (!dir.exists()) {
                boolean result = dir.mkdir();
                if (result) {
                    System.out.println("目录已创建");
                } else {
                    System.out.println("目录未能创建");
                }
            }
        }
        return dir;
    }

    private static void getDefault(Map<String, String> map, File dir, List<WdfConverter> wdfConverter) throws IOException {
        String sciNum = map.get("静立");
        serialize(sciNum, "站立", wdfConverter, dir);
        sciNum = map.get("行走");
        serialize(sciNum, "行走", wdfConverter, dir);
    }

    private static void getFight(Map<String, String> map, File dir, List<WdfConverter> wdfConverter) throws IOException {
        String sciNum = map.get("攻击");
        serialize(sciNum, "攻击", wdfConverter, dir);
        sciNum = map.get("死亡");
        serialize(sciNum, "死亡", wdfConverter, dir);
        sciNum = map.get("防御");
        serialize(sciNum, "防御", wdfConverter, dir);
        sciNum = map.get("待战");
        serialize(sciNum, "待战", wdfConverter, dir);
        sciNum = map.get("施法");
        serialize(sciNum, "施法", wdfConverter, dir);
        sciNum = map.get("跑去");
        serialize(sciNum, "逃跑", wdfConverter, dir);
        sciNum = map.get("挨打");
        serialize(sciNum, "挨揍", wdfConverter, dir);
    }

    private static void serialize(String sciNum, String name, List<WdfConverter> wdfConverter, File dir) throws IOException {
        if (sciNum != null) {
            if (sciNum.endsWith(".0") && !sciNum.contains("E")) {
                sciNum = sciNum.replace(".0", "");
            }
            BigDecimal bd = new BigDecimal(sciNum);
            String normalNum = bd.toPlainString();
            extracted(normalNum, name, wdfConverter, dir, true);
        }
    }

    private static void extracted(String index, String name, List<WdfConverter> wdfConverter, File dir, boolean flag) throws IOException {
        final File file = new File(dir.getAbsolutePath() + "/" + name + ".png");
        if (file.exists()) {
            return;
        }
        WasConverter wasConverter = null;
        String hexString;
        long creation;
        creation = Long.parseLong(index);
        System.out.println(" index:" + String.valueOf(creation) + " name:" + name);
        hexString = Long.toHexString(creation);
        for (WdfConverter converter : wdfConverter) {
            wasConverter = converter.getWasConverterMap().get(hexString);
            if (wasConverter != null) {
                break;
            }
        }
        if (wasConverter == null) {
            return;
        }
        wasConverter.analysis();
        for (ImageFile imageFile : wasConverter.getImageFiles()) {
            wasConverter.converterBufferedImage(imageFile);
        }
        Actuator.converterSpirit(dir.getAbsolutePath(), name, wasConverter);
        if (flag) {
            WasHeader header = wasConverter.getHeader();
            try (FileWriter fileWriter = new FileWriter(dir.getAbsolutePath() + File.separator + name + ".json")) {
                fileWriter.write(JSON.toJSONString(header));
            }
        }
    }


}